<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE HTML>
<html lang="en">
<head>
<base href="<%=basePath%>">
<link rel="stylesheet"
	href="${pageContext.request.contextPath}/css/bootstrap.min.css">
<link rel="stylesheet"
	href="${pageContext.request.contextPath}/css/main.css">
<script src="${pageContext.request.contextPath}/js/jquery.min.js"></script>
<script src="${pageContext.request.contextPath}/js/main.js"></script>
<script src="js/city2.js"></script>
<script type="text/javascript" src="js/citySelect2.js"></script>
<title>总部</title>


<style>
.main_div {
	min-width: 1000px
}

.center {
	width: 200px;
	height: 100px;
	background-color: #ccc;
	position: absolute;
	left: 50%;
	top: 50%;
	margin-left: -100px;
	margin-top: -50px;
	z-index: 10;
	text-align: center;
	line-height: 50px;
	border-radius: 6px;
}
.pageChange {
	float: right;
	color: #337ab7;
}

.pageChange>span {
	cursor: pointer
}

.pageChange>span:hover {
	color: blue
}
</style>
</head>
<body>
	<%@ include file="header.jsp"%>
	<%@ include file="left.jsp"%>
	<div id="index"
		style="position: absolute;left: 180px;top: 80px;bottom: 0;right: 0;">
		<section id="main">
			<div class="scrollbar1-1" id="style1-1">
				<div class="main_div" style="height:40px">
					<div class="main_title">
						<span>爆款审核</span>
					</div>
					<form class="form-inline" style="margin-top: 30px;margin-left: 20px">
					<input style="display:none" value="5" id="pageCount"
						name="pageCount" />
					<div class="form-group" id="city_4">
						<select class="form-control" id="prov4" data-code="510000"></select>
						<select class="form-control" id="city4" data-code="-1"></select>
						<select class="form-control" id="area4" data-code="-1"></select>
					</div>
					<div class="form-group" id="city_4">
						<select class="form-control" id="preview" name="checka" >
						   <option value="0">待审核</option>
						   <option value="1">审核通过</option>
						   <option value="2">审核失败</option>
						</select>						
					</div>
					<script>
					var selectVal = new CitySelect({
						data : data,
						provId : "#prov4",
						cityId : '#city4',
						areaId : '#area4'
					});
				</script>
					<button type="button" onclick="selectinfo()" class="btn btn-primary">立即查询</button>
					</form>
				</div>
				<div class="force-overflow1-1">
					<table id="showtable"
						class="table table-condensed table-bordered table-hover"
						style="text-align: center">
						<tr style="background-color: #59c7d2">
							<th style="text-align: center">序号</th>
							<th style="text-align: center">代理商</th>
							<th style="text-align: center">商品缩略图</th>
							<th style="text-align: center">爆款广告</th>
							<th style="text-align: center">商品名称</th>						
							
							<th style="text-align: center">审核结果</th>
							<th style="text-align: center">上架时间</th>
							<th style="text-align: center">查看详情</th>
						</tr>
					</table>
					<div class="pageChange">
						<span onclick="prePage()">&nbsp;&nbsp;上一页&nbsp;&nbsp;</span> <span
							onclick="nextPage()">&nbsp;&nbsp;下一页&nbsp;&nbsp;</span> <em>
							&nbsp; 第&nbsp;<span id="pageNum">1</span>&nbsp;页&nbsp;&nbsp;
						</em> <em>/&nbsp;&nbsp;共&nbsp;<span id="totalpage"></span>&nbsp;页
						</em> <em>&nbsp;&nbsp;&nbsp;跳到第<input id="searchInput"
							style="width:46px" maxlength="4" type="text">页
						</em>
						<button class="btn btn-primary" onclick="searchPage()">搜索</button>
					</div>
				</div>
			</div>
		</section>
		<script>
			$(function() {
				selectinfo();
			})
		
			
		
			function selectinfo() {
				var pageNum = $("#pageNum").html();
				var pageCount = $("#pageCount").val();
				var chackaVal = $("#preview").find("option:selected").val();
				var selectType2 = $("#area4").find("option:selected").val()
				if (selectType2==-1) {
					selectType2 = null
				}
				$.post(urls + "hotProductAction/getHotProductHead",
					{
						agentRegion : selectType2,
						pageNum : pageNum,
						pageCount : pageCount,
						checka : chackaVal						
					},
					function(data) {
						console.log(data)
						if (data) {
							var totalpage = data.totalpage;
							var orderlist = data.hotlist;
							var table = $("#showtable");
							$("tr").remove(".addtr");
							for (var i = 0; i < orderlist.length; i++) {
								var checka;
								if (orderlist[i].checka == 0) {
									checka = "未审核";
								} else if(orderlist[i].checka == 1){
									checka = "通过审核";
									$("#setButton").css("display","none");
									$("#setButton2").css("display","none");
								}else if(orderlist[i].checka == 2){
									checka = "未通过审核";
									$("#setButton").css("display","none");
									$("#setButton2").css("display","none");
								}
		
								var append = "<tr id='" + orderlist[i].id + "'  class='addtr'><td style='line-height:120px'>" + (i + 1) + "</td>" +
									"<td style='line-height:120px'>" + orderlist[i].agentName + "</td>" +
									"<td ><img style='width:250px;height:120px' src='/hots/" + orderlist[i].productSimg + "' alt='加载中'/> </td>" +
									"<td ><img style='width:250px;height:120px' src='/hots/" + orderlist[i].advertisement + "' alt='加载中'/> </td>" +
									"<td style='line-height:120px'>" + orderlist[i].productName + "</td>" +
									
									"<td style='line-height:120px'>" + checka + "</td>" +
									"<td style='line-height:120px'>" + orderlist[i].submitTime + "</td>" +
									"<td style='line-height:120px'><input onclick='detailinfo(\"" +
									 orderlist[i].productSimg +
									"|$" + orderlist[i].advertisement +
									"|$" + orderlist[i].barCode +
									"|$" + orderlist[i].productName +
									"|$" +orderlist[i].hotMoney +
									"|$" + orderlist[i].productDetail +
									"|$" + orderlist[i].id +
									"|$" + orderlist[i].goodstype +
									"|$" + orderlist[i].hotDetailImg +
									"|$" + orderlist[i].productBimg +
									 "\")' type='button' class='btn btn-primary' value='查看详情' /></td></tr>";
								table.append(append);
							}
							$("#totalpage").html(totalpage);
						}
					}
					, "json"
				)
			}
			function deletBurst(e) { //删除爆款
				if (confirm("是否删除爆款？")) {
					$.post(urls + "hotProductAction/deleteHotProduct",
						{
							hotId : e
						},
						function(res) {
							if (res) {
								$("#" + e).css("display", "none")
							} else {
								alert("删除商品失败")
							}
						})
				}
			}
			function detailinfo(e) { //点击修改
		
				$("#motai").css("display", "block");
				$("#main").css("display", "none");
			//var attr = e.split(" ");
			//$("#image").attr("src", attr[0]);
			//$("#productName2").val(attr[1]);
			//$("#productCard2").val(attr[2]);
			//$("#productPrice2").val(attr[3]);
			//$("#productDetail").val(attr[4])
			}
			function detailinfo(e) { //点击修改
				console.log(e)
				$("#motai").css("display", "block");
				$("#main").css("display", "none");
				var attr = e.split("|$");
				$("#image").attr("src", "/hots/" + attr[0]);
				$("#image2").attr("src", "/hots/" + attr[1]);
				$("#image3").attr("src", "/hots/" + attr[8]);
				$("#image4").attr("src", "/hots/" + attr[9]);
				$("#barCode").val(attr[2]);
				$("#productName").val(attr[3]);
				$("#productPrice").val(attr[4]);
				$("#productDetail").val(attr[5]);
				$("#id").val(attr[6]);
		
				$("#selectType2").find("option").val(attr[7]).attr("selected", true)
			}
		</script>
		<section id="motai" style="display:none">
			<div class="scrollbar1-1" id="style1-1">
				<div class="main_div" style="height: 560px;">
					<div class="main_title">
						<span>审核商品</span>
					</div>
					<form class="form-horizontal" enctype="multipart/form-data"
						style="margin-top: 30px" id="uploadForm">
						<div class="form-group">
							<label class="col-xs-2 control-label">商品分类：</label>
							<div class="col-xs-4">
								<div class="col-xs-12" id="goodstype"></div>
							</div>
						</div>
						<div class="form-group">
							<label class="col-xs-2 control-label">商品名称：</label>
							<div class="col-xs-3">
								<input type="text" class="form-control" id="productName"
									name="productName" placeholder="商品名称"> <input name="id"
									type="text" style="display:none" id="id">
							</div>
						</div>
						<div class="form-group">
							<label class="col-xs-2 control-label">商品条码：</label>
							<div class="col-xs-3">
								<input type="text" class="form-control" id="barCode"
									name="barCode" placeholder="商品条码">
							</div>
						</div>
						<div class="form-group">
							<label class="col-xs-2 control-label">商品价格：</label>
							<div class="col-xs-3">
								<input type="text" class="form-control" id="productPrice"
									maxlength="6" name="hotMoney" placeholder="商品价格">
							</div>
						</div>
						<div class="form-group">
							<label class="col-xs-2 control-label">略缩图上传：</label>
							<div class="col-xs-3">
								<input type="file" id="picFile" name="Thumbnail"
									onchange="selectImage(this);" /> <img id="image"
									style="width:105px;height:105px" src="" />
							</div>
							<label class="col-xs-2 control-label"
								style="text-align: left;color: #ff6c29">*必须上传略缩图（建议大小为210*210像素）</label>
						</div>
						<div class="form-group">
							<label class="col-xs-2 control-label">banner上传：</label>
							<div class="col-xs-3">
								<input type="file" id="bannerFile" name="banner"
									onchange="selectImage2(this);"> <input type="text"
									id="agentId" name="agentId" style="display:none"> <img
									id="image2" style="width:375px;height:150px" src="" />
							</div>
							<label class="col-xs-5 control-label"
								style="text-align: left;color: #ff6c29">*必须上传广告图片（建议大小为750*300像素）</label>
						</div>
						<div class="form-group">
							<label class="col-xs-2 control-label">商品图片：</label>
							<div class="col-xs-3">
								<input type="file" id="bigpicFile" name="bigpicFile"
									onchange="selectImage4(this);"> <img
									id="image4" style="width:375px;height:375px" src="" />
							</div>
							<label class="col-xs-5 control-label"
								style="text-align: left;color: #ff6c29">*必须上传商品图片（建议大小为750*750像素）</label>
						</div>
						<div class="form-group">
							<label class="col-xs-2 control-label">商品详情图片：</label>
							<div class="col-xs-3">
								<input type="file" id="hotDetailFile" name="hotDetailFile"
									onchange="selectImage3(this);">  <img
									id="image3" style="width:375px;" src="" />
							</div>
							<label class="col-xs-5 control-label"
								style="text-align: left;color: #ff6c29">*必须上传商品详情图片（建议宽度为750像素）</label>
						</div>
						<div class="form-group">
							<label class="col-xs-2 control-label">商品介绍：</label>
							<div class="col-xs-4">
								<textarea class="col-xs-12" rows="5" id="productDetail"
									name="productDetail"></textarea>
							</div>

						</div>

						<div class="col-xs-4 col-xs-offset-2">
							<button id="setButton" class="col-xs-4 btn btn-success"
								type="button" onclick="doPass(1)">通过</button>
							<button id="setButton2" onclick="doPass(2)"
								class="col-xs-offset-1 col-xs-4 btn btn-primary" type="button">不通过</button>
						</div>

					</form>
				</div>
			</div>
		</section>
	</div>
	<script>
	
		function doPass(types) { //是否审核通过
			$.post(urls + "headAction/checkHotProduct",
				{
					id : $("#id").val(),
					checka : types
				},
				function(res) {
					if (res) {
					 alert("操作成功")
						selectinfo();
						$("#motai").css("display", "none");
						$("#main").css("display", "block");
					}
				}
			)
		}
		var image = '';
		function selectImage(file) { //显示图片
			if (!file.files || !file.files[0]) {
				return;
			}
			var reader = new FileReader();
			reader.onload = function(evt) {
				document.getElementById('image').src = evt.target.result;
				image = evt.target.result;
			};
			reader.readAsDataURL(file.files[0]);
		}
		function selectImage2(file) { //显示图片
			if (!file.files || !file.files[0]) {
				return;
			}
			var reader = new FileReader();
			reader.onload = function(evt) {
				document.getElementById('image2').src = evt.target.result;
				image = evt.target.result;
			};
			reader.readAsDataURL(file.files[0]);
		}
		function selectImage3(file) { //显示图片
			if (!file.files || !file.files[0]) {
				return;
			}
			var reader = new FileReader();
			reader.onload = function(evt) {
				document.getElementById('image3').src = evt.target.result;
				image = evt.target.result;
			};
			reader.readAsDataURL(file.files[0]);
		}
		function selectImage4(file) { //显示图片
			if (!file.files || !file.files[0]) {
				return;
			}
			var reader = new FileReader();
			reader.onload = function(evt) {
				document.getElementById('image4').src = evt.target.result;
				image = evt.target.result;
			};
			reader.readAsDataURL(file.files[0]);
		}
	</script>
</body>
</html>
